package com.ruoyi.service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.entity.SxfBusinessPktToCloud;
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
import com.ruoyi.mapper.SxfBusinessPktToCloudMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.SxfBusinessPktToCloudFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 本地端和云端业务关系表 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-20
 */
@Service
public class SxfBusinessPktToCloudService extends ServiceImpl<SxfBusinessPktToCloudMapper, SxfBusinessPktToCloud> {

	public ResponseData create(SxfBusinessPktToCloudFrom sxfBusinessPktToCloud) {
		SxfBusinessPktToCloud entity = transformationFrom(sxfBusinessPktToCloud);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(SxfBusinessPktToCloudFrom sxfBusinessPktToCloud) {
		if(findById(sxfBusinessPktToCloud.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfBusinessPktToCloud entity = transformationFrom(sxfBusinessPktToCloud);
		entity.setId(sxfBusinessPktToCloud.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public SxfBusinessPktToCloud transformationFrom(SxfBusinessPktToCloudFrom sxfBusinessPktToCloud) {
		SxfBusinessPktToCloud entity = new SxfBusinessPktToCloud();
		entity.setBizId(sxfBusinessPktToCloud.getBizId());
		entity.setCarBusinessId(sxfBusinessPktToCloud.getCarBusinessId());
		entity.setSpaceBusinessId(sxfBusinessPktToCloud.getSpaceBusinessId());
		entity.setType(sxfBusinessPktToCloud.getType());
		entity.setPlCode(sxfBusinessPktToCloud.getPlCode());
		entity.setPlateNumber(sxfBusinessPktToCloud.getPlateNumber());
		entity.setCreator(sxfBusinessPktToCloud.getCreator());
		entity.setCreateTime(sxfBusinessPktToCloud.getCreateTime());
		entity.setModifier(sxfBusinessPktToCloud.getModifier());
		entity.setModifyTime(sxfBusinessPktToCloud.getModifyTime());
		entity.setToId(sxfBusinessPktToCloud.getToId());
		return entity;
	}

	public SxfBusinessPktToCloudFrom transformationBean(SxfBusinessPktToCloud sxfBusinessPktToCloud) {
		SxfBusinessPktToCloudFrom from = new SxfBusinessPktToCloudFrom();
		from.setBizId(sxfBusinessPktToCloud.getBizId());
		from.setCarBusinessId(sxfBusinessPktToCloud.getCarBusinessId());
		from.setSpaceBusinessId(sxfBusinessPktToCloud.getSpaceBusinessId());
		from.setType(sxfBusinessPktToCloud.getType());
		from.setPlCode(sxfBusinessPktToCloud.getPlCode());
		from.setPlateNumber(sxfBusinessPktToCloud.getPlateNumber());
		from.setCreator(sxfBusinessPktToCloud.getCreator());
		from.setCreateTime(sxfBusinessPktToCloud.getCreateTime());
		from.setModifier(sxfBusinessPktToCloud.getModifier());
		from.setModifyTime(sxfBusinessPktToCloud.getModifyTime());
		from.setToId(sxfBusinessPktToCloud.getToId());

		return from;
	}

	
	public SxfBusinessPktToCloudFrom findById(String id) {
		SxfBusinessPktToCloud entity = this.getOne(new QueryWrapper<SxfBusinessPktToCloud>().lambda()
				.eq(SxfBusinessPktToCloud::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		SxfBusinessPktToCloud sxfBusinessPktToCloud = new SxfBusinessPktToCloud();
		sxfBusinessPktToCloud.setId(id);
		this.updateById(sxfBusinessPktToCloud);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, SxfBusinessPktToCloudFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<SxfBusinessPktToCloud>().lambda()
				.eq(ibean.getBizId() != null, SxfBusinessPktToCloud::getBizId, ibean.getBizId())
				.eq(ibean.getCarBusinessId() != null, SxfBusinessPktToCloud::getCarBusinessId, ibean.getCarBusinessId())
				.eq(ibean.getSpaceBusinessId() != null, SxfBusinessPktToCloud::getSpaceBusinessId, ibean.getSpaceBusinessId())
				.eq(StringUtils.isNotEmpty(ibean.getType()), SxfBusinessPktToCloud::getType, ibean.getType())
				.eq(StringUtils.isNotEmpty(ibean.getPlCode()), SxfBusinessPktToCloud::getPlCode, ibean.getPlCode())
				.eq(StringUtils.isNotEmpty(ibean.getPlateNumber()), SxfBusinessPktToCloud::getPlateNumber, ibean.getPlateNumber())
				.eq(ibean.getCreator() != null, SxfBusinessPktToCloud::getCreator, ibean.getCreator())
				.eq(ibean.getCreateTime() != null, SxfBusinessPktToCloud::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifier() != null, SxfBusinessPktToCloud::getModifier, ibean.getModifier())
				.eq(ibean.getModifyTime() != null, SxfBusinessPktToCloud::getModifyTime, ibean.getModifyTime())
				.eq(ibean.getToId() != null, SxfBusinessPktToCloud::getToId, ibean.getToId())
				);
	}
}
